package com.qyhl.webtv.module_news.news.newslist;


import com.qyhl.webtv.commonlib.entity.news.AdvHomeBean;
import com.qyhl.webtv.commonlib.entity.news.NewsBean;

import java.util.List;

/**
 * Created by qyhl on 2017/11/29.
 */

public class NewsListPresenter implements NewsListContract.NewsListPresenter {
    private NewsListContract.NewsListView mView;
    private NewsListModel mModel;

    public NewsListPresenter(NewsListContract.NewsListView mView) {
        this.mView = mView;
        this.mModel = new NewsListModel(this);
    }

    @Override
    public void getDatas(String sectionId, String newsId) {
        mModel.getDatas(sectionId, newsId);
    }

    @Override
    public void getHeaderNum(String sectionId,String url) {
        try {
            mModel.getHeaderNum(sectionId,url);
        } catch (Exception e) {
            mView.setHeaderError();
        }

    }

    @Override
    public void getAdvData(String sectionId) {
        mModel.getAdvData(sectionId);
    }

    @Override
    public void setDatas(List<NewsBean> beanList, boolean isMore) {
        mView.setDatas(beanList, isMore);
    }

    @Override
    public void setError(int code, String msg) {
        switch (code) {
            case 0:
                mView.setNetError(msg);
                break;
            case 1:
                mView.showMessage(msg);
                break;
            case 2:
                mView.setEmpty(msg);
                break;
            case 3:
                mView.setError(msg);
                break;
            case 4:
                mView.showLog(msg);
                break;
            case 5:
                mView.showMessage(msg);
                break;
            default:
                break;
        }
    }

    @Override
    public void setHeaderNum(int num) {
        mView.setHeaderNum(num);
    }

    @Override
    public void setHeaderError() {
        mView.setHeaderError();
    }

    @Override
    public void setAdvData(List<AdvHomeBean> beanList) {
        mView.setAdvData(beanList);
    }

    @Override
    public void setAdvError(String msg) {
        mView.setAdvError(msg);
    }
}
